package com.mdd.common.util.weifengqi.report;

import com.alibaba.fastjson.JSONObject;
import com.mdd.common.util.HttpUtils;
import org.apache.commons.math3.util.Pair;

import java.util.HashMap;
import java.util.Map;

/**
 * 财政补贴报告
 */
public class FinancialSubsidyReportUtil {

    //获取财政补贴报告---接口地址
    public static final String url="https://api.enterpriseservice.cn/mini-program-index-api/fiscal_subsidies/report/fiscal_subsidies_analysis/document";
    //取报告---渠道编码号
    public static final String interfaceCode = "a6343b19103946a28401e3329b2f6899HA2TO";
    //取报告---加密串
    public static final String secretKey = "231ntTEDmFPlYKAJdteqK5We22jbd7TT2WESPFHPA/h1lQFp4mkBp6QZvik8D8N3";


    /**
     * 获取财政补贴报告
     * @param order_no
     * @param tax_no
     *  * api文档地址:https://www.wfq2020.com/api-channel/doc-center
     *      接口路径：https://api.enterpriseservice.cn/mini-program-index-api/fiscal_subsidies/report/fiscal_subsidies_analysis/document
     *      请求类型：none
     *      请求格式：GET
     *      描述：获取财政补贴文档报告(pdf-doc)(勾选此接口后不再支持其他财政补贴详情接口)
     * @return
     */
    public static Pair<Boolean, String> getFinancialSubsidyReport(String order_no, String tax_no) {
        Map<String, String> map = new HashMap<>();
        map.put("interfaceCode", interfaceCode);
        map.put("secretKey", secretKey);
        //单次
        if(order_no!=null && !order_no.isEmpty()){
            map.put("order_no", order_no);
        }
        //批次
        if(tax_no!=null && !tax_no.isEmpty()){
            map.put("tax_no", tax_no);
        }
        String result = HttpUtils.sendGetParams(url, map);
        if(result!=null && !result.isEmpty()){
            JSONObject jsonObject = JSONObject.parseObject(result);
            if(jsonObject.getInteger("code")==200){
                String report_url = jsonObject.getJSONObject("data").getString("report_url");
                return new Pair<>(true, report_url);
            }
            return new Pair<>(false, jsonObject.toString());
        }
        return new Pair<>(false, "");
    }

}
